<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $table = 'orders';

    protected $fillable = [
    	'openid',
    	'order_type',
    	'order_number',
    	'order_price',
    	'order_status',
    	'goods_info',
        'service_info',
    	'order_remark',
        'pay_status',
    	'hotel_id',
    	'room_id'
    ];

    protected $appends = [
        'order_type_explain',
        'pay_status_explain',
        'order_status_explain'

    ];

    const TYPE_GOODS = 1;

    const TYPE_SERVICE = 0;

    public static $TYPE = [
        self::TYPE_GOODS => '购买商品',
        self::TYPE_SERVICE => '申请服务'
    ];

    public function getOrderTypeExplainAttribute(){
        if(array_key_exists('order_type',$this->attributes)){
            return $this->attributes['order_type_explain'] = self::$TYPE[$this->attributes['order_type']];
        }
    }

    const PAY_STATUS_SUCCESS = 1;

    const PAY_STATUS_FAIL = 0;

    public static $PAYSTATUS = [
        self::PAY_STATUS_SUCCESS = '已支付',
        self::PAY_STATUS_FAIL = '未支付'
    ];

    public function getPayStatusExplainAttribute(){
        if(array_key_exists('pay_status',$this->attributes)){
            return $this->attributes['pay_status_explain'] = self::$TYPE[$this->attributes['pay_status']];
        }
    }

    const ORDER_STATUS_WAIT = 1;

    const ORDER_STATUS_ACCEPT = 2;

    const ORDER_STATUS_COMPLETS = 3;

    public static $ORDERSTATUS = [
        self::ORDER_STATUS_WAIT = '待受理',
        self::ORDER_STATUS_ACCEPT = '进行中',
        self::ORDER_STATUS_COMPLETS = '已完成'
    ];

    public function getOrderStatusExplainAttribute(){
        if(array_key_exists('order_status',$this->attributes)){
            return $this->attributes['order_status_explain'] = self::$TYPE[$this->attributes['order_status']];
        }
    }

    public function hotel(){
        return $this->belongsTo('App\Models\Hotel');
    }

    public function room(){
        return $this->belongsTo('App\Models\room');
    }
}
